package ee.karileet.productcatalogue.service.impl;

import ee.karileet.productcatalogue.dao.IGroupHome;
import ee.karileet.productcatalogue.dao.impl.GroupHome;
import ee.karileet.productcatalogue.model.Group;
import ee.karileet.productcatalogue.service.IGroup;

public class GroupSrv implements IGroup {
	
	private IGroupHome home;
	
	public GroupSrv() {
		home = new GroupHome();
	}
	
	public boolean addGroup(Group group) {
		home.save(group);
		return false;
	}

	public Group getGroup(int groupId) throws Exception {
		if (!(groupId > 0)) throw new Exception("ID must be greater than 0");
		return home.findById(groupId);
	}

	public java.util.Set<Group> listGroups() {
		return new java.util.HashSet<Group>(home.findAll());
	}

	public void removeGroup(int groupId) throws Exception {
		if (!(groupId > 0)) throw new Exception("ID must be greater than 0");
		Group g = home.findById(groupId);
		home.delete(g);
	}

	public boolean updateGroup(Group group) {
		// TODO Auto-generated method stub
		return false;
	}

}
